{extends file='layout/main.html'}
{block name="main"}
<div class="main_title">
	<h2>添加视频/图片</h2>
</div>


<form action="?url=item/update&id={$smarty.get.id}" method="post" enctype="multipart/form-data" accept-charset="utf-8">

<div class="con_blk">
  <h3 class="light_gray">类型</h3>
	图片：
	<input type="radio" name="info[type]" value="0" {if $item.type==0} checked {/if}>&nbsp;&nbsp;&nbsp;&nbsp;
	视频：
	<input type="radio" name="info[type]" value="1" {if $item.type==1} checked {/if}>
</div>
{if $item.type==1}
<script type="text/javascript" charset="utf-8">
	$(function(){
		
		var flash = showFlash('youku.com', '{$item.data.flashvar}');
		$(".flash_play").html(flash);
		
	});
</script>
{/if}

<div class="con_blk type_data_video">
  <h3 class="light_gray">视频信息</h3>
	<div class="flash_play"></div>
	<input type="text" name="type_data_video" class="text" value="{if $item.type==1}{$item.data.source}{/if}">
</div>


<div class="con_blk type_data_img">
  <h3 class="light_gray">图片信息</h3>
  {if $item.type==0}
  <img src="/attachments{$item.data}" />
  {include file="lib/upload.html" upload_name="type_data_img" value=$item.data}
  {else}
  {include file="lib/upload.html" upload_name="type_data_img"}
  {/if}

</div>


<div class="con_blk">
  <h3 class="light_gray">价格</h3>
	<input name="info[price]" type="text" class="text" value="{$item.price}">
</div>

<div class="con_blk">
  <h3 class="light_gray">标题</h3>
	<input name="info[title]" type="text" class="text" value="{$item.title}">
</div>

<div class="con_blk attr_q">
  <h3 class="light_gray">附件<a href="javascript://" class="add_one">添加一个</a></h3>
	<table border="0" cellspacing="5" cellpadding="5">
		<tr><th>文件名</th><th>尺寸</th><th>添加时间</th><th>操作</th></tr>
		{foreach $item_att as $v}
			<tr>
				<td><a href="{$smarty.const.SITE_URL_R}/attachments{$v.data}">{$v.data}</a></td>
				<td>
					{foreach $size as $k}
						{if $k.id==$v.size_id}
							{$k.name}
						{/if}
				  	{/foreach}
				</td>
				<td>{date('Y-m-d', $v.add_time)}</td>
				<td><a href="#"  onclick="return del_attr(this,{$v.id})">删除</a></td>
			</tr>
		{/foreach}
	</table>
				
		<br /><br />
		<div class="attr_info clearfix pb10">
			<input name="attr[1]" type="file" >
			<select name="attr_size[1]" rel="raw">
			  <option value="0">无</option>
			  {foreach $size as $val}
			  <option value="{$val.id}" >{$val.name}</option>
			  {/foreach}
			</select>
		</div>
</div>


<script type="text/javascript" charset="utf-8">
	var i = 1;
	$(".add_one").click(function(){
		i++;
		var html= '<div class="attr_info clearfix pb10">\
			<input name="attr['+i+']" type="file" >\
			<select name="attr_size['+i+']">\
			  <option value="0">无</option>\
			  {foreach $size as $val}
			  <option value="{$val.id}" >{$val.name}</option>\
			  {/foreach}
			</select>&nbsp;&nbsp;&nbsp;<a href="javascript://" class="rm_attr">删除</a>\
		</div>';
		$(".attr_q").append(html);
		$('.rm_attr').click(function(){
			$(this).parent().remove();
		})
	});
	
	function del_attr (tis,id) {
		if (confirm('确认删除？')) {
			$.get('?url=item/delete_attr&id='+id, function(i){
				if (i=='1') {
					$(tis).parents('tr').remove();
				};
			});
		};
		return false;
	}

</script>

<div class="con_blk">
  <h3 class="light_gray">内容</h3>
	<textarea name="info[content]" rows="8" cols="40">{$item.content}</textarea>
</div>





{foreach $cate_gory as $val}
	{if !$val.parent_id}
	<div class="con_blk">
	  <h3 class="light_gray">{$val.name}</h3>
	&nbsp;&nbsp;&nbsp;&nbsp;
		{foreach $cate_gory as $v}
			{if $v.parent_id==$val.id}
				{$v.name}:<input type="checkbox" name="item_ralation[]" value="{$v.id}" {if $item_ralation}{if in_array($v.id, $item_ralation)} checked {/if}{/if}>&nbsp;&nbsp;
			{/if}
		{/foreach}
	</div>
	{/if}
{/foreach}

</form>

<div class="btn_blk b_t">
	<div class="fr">
		<a href="#" class="btn2 fr ml20 cancel">取消</a>
		<a href="#" class="btn1 fr save">确定</a>
	</div>
</div>
<script type="text/javascript" charset="utf-8">

	$(function(){
		check_radio();
	});
	
	function  check_radio() {
		var radio = $("input[name='info[type]']:checked");
		var vedio = $(".type_data_video");
		var img = $(".type_data_img");
		if (radio.val() == '1') {
			img.hide();
			vedio.show();
		}else{
			vedio.hide();
			img.show();
		};
	}
	
	$("input[name='info[type]']").click(function(){
		check_radio();
	});
	
</script>
{/block}